package com.smile.controller;

import cn.dev33.satoken.annotation.SaIgnore;
import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.Result;
import com.smile.model.dto.request.*;
import com.smile.model.request.*;
import com.smile.commons.page.R;
import com.smile.service.AirlineService;
import com.smile.service.FlyService;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/airline")
public class AirlineController {

    @Autowired
    private AirlineService airlineService;


    /**
     * 执行航线任务
     *
     * @param executeAirlineTaskRequest
     * @return
     * @throws MqttException
     */
    @SaIgnore
    @PostMapping("/executeAirlineTask")
    public R<Result> executeAirlineTask(@RequestBody ExecuteAirlineTaskRequest executeAirlineTaskRequest) throws Exception {
        ExecuteAirlineTaskRequestDTO executeAirlineTaskRequestDTO = BeanUtil.copyProperties(executeAirlineTaskRequest, ExecuteAirlineTaskRequestDTO.class);
        Result result = airlineService.executeAirlineTask(executeAirlineTaskRequestDTO);
        return R.ok(result);
    }

    /**
     * 空中下发航线
     *
     * @param inFlightWaylineDeliverRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/inFlightWaylineDeliver")
    public R<Void> inFlightWaylineDeliver(InFlightWaylineDeliverRequest inFlightWaylineDeliverRequest) throws MqttException {
        InFlightWaylineDeliverRequestDTO inFlightWaylineDeliverRequestDTO = BeanUtil.copyProperties(inFlightWaylineDeliverRequest, InFlightWaylineDeliverRequestDTO.class);
        airlineService.inFlightWaylineDeliver(inFlightWaylineDeliverRequestDTO);
        return R.ok();
    }

    /**
     * 暂停航线
     *
     * @param flighttaskPauseRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/flighttaskPause")
    public R<Void> flighttaskPause(@RequestBody FlighttaskPauseRequest flighttaskPauseRequest) throws MqttException {
        FlighttaskPauseRequestDTO flighttaskPauseRequestDTO = BeanUtil.copyProperties(flighttaskPauseRequest, FlighttaskPauseRequestDTO.class);
        airlineService.flighttaskPause(flighttaskPauseRequestDTO);
        return R.ok();
    }

    /**
     * 恢复航线
     */
    @PostMapping("/flighttaskRecovery")
    public R<Void> flighttaskRecovery(FlighttaskPauseRequest flighttaskPauseRequest) throws MqttException {
//        airlineService.
        FlighttaskPauseRequestDTO flighttaskPauseRequestDTO = BeanUtil.copyProperties(flighttaskPauseRequest, FlighttaskPauseRequestDTO.class);
        airlineService.flighttaskRecovery(flighttaskPauseRequestDTO);
        return R.ok();
    }

    /**
     * 暂停空中航线
     *
     * @param inFlightWaylineStopRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/inFlightWaylineStop")
    public R<Void> inFlightWaylineStop(InFlightWaylineStopRequest inFlightWaylineStopRequest) throws MqttException {
        InFlightWaylineStopRequestDTO inFlightWaylineDeliverRequestDTO = BeanUtil.copyProperties(inFlightWaylineStopRequest, InFlightWaylineStopRequestDTO.class);
        airlineService.inFlightWaylineStop(inFlightWaylineDeliverRequestDTO);
        return R.ok();
    }

    /**
     * 恢复空中航线
     *
     * @param inFlightWaylineRecoverRequest
     * @return
     * @throws MqttException
     */
    @PostMapping("/inFlightWaylineRecover")
    public R<Void> inFlightWaylineRecover(InFlightWaylineRecoverRequest inFlightWaylineRecoverRequest) throws MqttException {
        InFlightWaylineRecoverRequestDTO inFlightWaylineRecoverRequestDTO = BeanUtil.copyProperties(inFlightWaylineRecoverRequest, InFlightWaylineRecoverRequestDTO.class);
        airlineService.inFlightWaylineRecover(inFlightWaylineRecoverRequestDTO);
        return R.ok();
    }


    @PostMapping("/inFlightWaylineCancel")
    public R<Void> inFlightWaylineCancel(InFlightWaylineDeliverRequest inFlightWaylineDeliverRequest) throws MqttException {
        InFlightWaylineDeliverRequestDTO inFlightWaylineDeliverRequestDTO = BeanUtil.copyProperties(inFlightWaylineDeliverRequest, InFlightWaylineDeliverRequestDTO.class);
        airlineService.inFlightWaylineCancel(inFlightWaylineDeliverRequestDTO);
        return R.ok();
    }

    @PostMapping("/flyToPointStop")
    public R<Void> flyToPointStop(@RequestBody FlyToPointStopRequest flyToPointStopRequest) throws MqttException {
        FlyToPointStopRequestDTO flyToPointStopRequestDTO = BeanUtil.copyProperties(flyToPointStopRequest, FlyToPointStopRequestDTO.class);
        airlineService.flyToPointStop(flyToPointStopRequestDTO);

        return R.ok();
    }

}
